# utils.py
import logging
from flask import jsonify

SUCCESS = 200
FAILURE = 500
#
# 统一返回结果
def build_fail_response(message = 'fail', params = '无参数'):
    response = {
        "data": [],
        "message": message,
        "code": 500
    }
    logging.error(f"处理请求时出现错误: {message}，请求参数： {params}")
    return jsonify(response), 500

def build_success_response(data = [], message = 'success'):
    response = {
        "data": data,
        "message": message,
        "code": 200
    }
    return jsonify(response), 200


def confirm_params_type(request):
    if request.method == 'GET':
        # 处理GET请求，返回request.args
        data = request.args.to_dict()
    else:
        # 处理POST请求，返回request.json
        data = request.json
    return data